package com.smsc.headend.task.engine.service.task;

import com.smsc.headend.module.data.dto.TaskDataDTO;
import com.smsc.headend.module.data.dto.TaskPacketDTO;
import com.smsc.headend.module.task.dto.*;
import com.smsc.headend.module.task.entity.DeviceTask;
import com.smsc.headend.task.engine.po.CollectTask;
import com.smsc.headend.task.engine.po.TaskEndStatusPo;

import java.util.List;
import java.util.Set;

public interface TaskService {


    /**
     * start execute task
     * @param task
     * @return
     */
    TaskEndStatusPo doStartTask(Task task);

    /**
     * handle response from con
     * @param atomicTaskNo
     */
    void atomicTaskResponse(ConnectorTaskResult atomicTaskNo) throws IllegalAccessException, InstantiationException;

//    /**
//     * get executing atomic task by taskNo
//     * @param taskNo
//     * @return Task instance
//     */
//    AtomicTask getProcessingAtomicTask(String taskNo);


//    /**
//     * get idle terminal queues with tasks waiting to execute
//     * @param terminalKeys
//     * @return
//     */
//    List<String> getIdleTerminalQueue(List<String> terminalKeys);


    /**
     * emit a atomic task in a operation task
     * @param task
     * @param previousAtomicTaskNo
     * @return
     */
    TaskEndStatusPo emitAtomicTask(Task task, String previousAtomicTaskNo) throws IllegalAccessException, InstantiationException;

    /**
     * add atomic task to queue of a operation Task
     * @see Task
     * @param atomicTask
     */
    void pushAtomicTask(AtomicTask atomicTask);

    /**
     * processing keys in redis where save state of atomic task
     * @return
     */
    Set<String> getAtomicTaskProcessingList();

    /**
     * function for check atomic task if time over
     * @param processingList
     */
    void checkTimeOver(Set<String> processingList) throws InstantiationException, IllegalAccessException;

    /**
     * 获取已经取回的设备数据
     * @param taskNo
     * @return
     */
    List<TaskDataDTO> taskDataPopAll(String taskNo);

    Task getTask(Long terminalId, Integer priority);

    /**
     * 获取任务正在执行的原子任务
     * @param taskNo
     * @return
     */
    String getProcessingAtomicTaskByTaskNo(String taskNo);

    /**
     * 中断COM下的任务
     * @param comId
     */
    void interruptComTask(Long comId);

    Long getDeviceId(Task task);

    Long getDeviceType(Task task);

    /**
     * 获取task的报文内容
     * @param taskNo
     * @return
     */
    List<TaskPacketDTO> getTaskPacket(String taskNo);

    /**
     * 获取task的报文内容
     *
     * @param deviceTask 设备对应的LOG_DEVICE_TASK
     * @return
     */
    List<TaskPacketDTO> getTaskPacket(DeviceTask deviceTask);


    /**
     * 计算缺点生成补抄任务
     */
    void autoRecollectCheck();

    CollectTask updatePreviousCollectTask(Task oldTask, Task collectionTask, Long startTime, Long endTime, CollectTask overLapTask);




    Task getTaskByNo(String taskNo);

    void handleTaskEndPo(TaskEndStatusPo taskEndStatusPo, Task task);

    int checkAtomicTaskOverTime(String atomicTaskNo);

    boolean updateTask(Task task);

    void sendTaskToGenerator(Task task);

    void saveRejectedTask(Runnable r);

    void scheduleCheckExecutor();

    void taskExecutionPoolCheck();

}
